import React, { Component } from 'react'
import '../../assets/css/details.css'
import { Toast } from 'antd-mobile';
import {getgoodsinfo,cartadd} from '../../request/api'
export default class details extends Component {
    constructor(){
        super()
        this.state={
            good:[]
        }
    }
    componentDidMount(){
        getgoodsinfo(this.props.match.params).then(res=>{
           
            this.setState({good:res.list[0]})
             console.log(this.state.good);
        })
    }
    catr(e,id){
        e.stopPropagation()
       
        if(JSON.parse(sessionStorage.getItem('user'))==null){
            this.props.history.push('/login')
        }else {
         let uid=JSON.parse(sessionStorage.getItem('user')).uid
       let a={
           uid,
           type:1,
           goodsid:id,
           num:1
       }

       cartadd(a).then(res=>{
           if(res.code==200){
               Toast.success('添加成功', 1);
           }
       })
        }
        
       
    }
    render() {
        return (
            <div>
                
                <div className="box w">
                    <div className="top"> 
                    <i className='back' onClick={()=>this.props.history.goBack()}>&lt;</i>
                        <ul>
                           
                            <li><a href="">商品</a></li>
                            <li><a href="">评价</a></li>
                            <li><a href="">详情</a></li>
                            <li><a href="">推荐</a></li>
                        </ul>
                        <a href=""><img src={this.state.good.img} alt="" /></a>
                        <i className="iconfont icon-fenxiang"></i>
                        <div className="cont">
                            <p>
                                <span><i>&yen;</i>{this.state.good.price}</span>
                                <s>&yen;{this.state.good.market_price}</s>
                                <i className='iconfont icon-shoucang'>
                                    <br />
                收藏
            </i>
                            </p>
                            <p><a href="">{this.state.good.goodsname}</a> </p>
                            <p><a href="">{this.state.good.description}</a> </p>
                            <span className="orange">
                                <a href="">
                                    11.11限时299元起
                </a>
                            </span>
                            <p>
                                <a href=""> 此商品于2020-11-11,00点结束闪购特卖，品牌美妆闪购专场</a>
                                <span><a href=""> 查看 &gt;</a></span>
                            </p>
                        </div>
                    </div>
                    <div className="bottom">
                        <div className="row1">
                            <div className="left"><span>领券</span></div>
                            <div className="right">
                                <i>&yen;300</i>
                                <i>&yen;20</i>
                                <i>&yen;10</i>

                            </div>
                        </div>
                        <div className="row2">
                            <div className="left"><span>分期</span></div>
                            <div className="right">
                                <a href="">
                                    可选3/6/12期
                        <span>&gt;</span>
                                </a>

                            </div>
                        </div>
                    </div>
                </div>
                <div className="foot">
                    <div className="left">
                        <a href="">
                            <i className="iconfont icon-jiaoliu"></i>
                            <span>客服</span>
                        </a>
                        <a href="">
                            <i className="iconfont icon-dianpu"></i>
                            <span>店铺</span>
                        </a>
                        <a href="">
                            <i className="iconfont icon-gouwuche"></i>
                            <span>购物车</span>
                        </a>
                    </div>
                    <div className="content" onClick={(e)=>this.catr(e,this.state.goodsid)}>加入购物车</div>
                    <div className="right">立即购买</div>
                </div>
            </div>
        )
    }
}
